﻿using SudukuSolver_Mvvm.ViewModels;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Reflection.Metadata.Ecma335;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;

namespace SudukuSolver_Mvvm.ValueConverters
{
    public class CellValueToTextConverter : IValueConverter
    {
        // 将数独的格子的数据转换成要显示字符串
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value is int v && v != 0) return v.ToString();
            return "";
        }

        // 将显示的字符串转换成数字
        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            int num;
            int.TryParse(value as string, out num); // value是null和空字符串时都会转换成0
            return num;
        }
    }
}
